<?php
$this->load->view('include/own_community_session');
?>

<style>
    input[type="checkbox"]{
        display:none;
    }   
    .box{

        cursor:pointer;
        width: 100%;
        height: 70px;

        margin-bottom: 0.500em;

        border-bottom: 1px solid #bdcd00;

    }
    .box2{

        cursor:pointer;
        width: 100%;
        height: 50px;
        border-bottom: 1px solid #bdcd00;

    }

    .data{
        font-size:0.90em;
    }

    .inputbox{
        width: auto;
        height:auto;
        float:left;
        color: #5c5c5b;

        clear:both;

    }

    .checkedAdvanced{
        position:absolute;
        right:0;
        z-index: 1;
        background-image:url('<?php echo base_url('/images/check.png'); ?>');
        height: 41px;
        width: 44px;
        margin-top: 20px;
        background-repeat:no-repeat;

    }

    .checked{
        position:absolute;
        right:0;
        z-index: 1;
        margin-top: 5px;

        background-image:url('<?php echo base_url('/images/check.png'); ?>');
        height: 41px;
        width: 44px;
        background-repeat:no-repeat;

    }
</style>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
    $(function(){
        c = '<?php echo($counter) ?>';
       
        
    });
    
 
    function divClick(id, counter){
     
    
        if($('.checkbox'+id).attr("checked")){
            
            // uncheck
            $('.checkbox'+id).prop("checked", false);
            $('.chkAdvanced'+id).removeClass("checkedAdvanced");
            $('.chk'+id).removeClass("checked");
            
            myFunction(id, counter);
        }else{
            // check
            
            $('.checkbox'+id).prop("checked", true);
            
            $('.chkAdvanced'+id).addClass("checkedAdvanced");
            $('.chk'+id).addClass("checked");
            myFunction(id, counter);
        }
     
     
    }
    function myFunction(id, counter){
        
        
     
        
        
        if($('.checkbox'+id).attr('checked')){
                 
            community = $('#community'+id).val();
            count = counter;
            if(c < 3){
                $.ajax({
                    url: '<?php echo(base_url('selecties/toevoegen')); ?>',
                    type: 'post',
                    data: 'community='+ community +'&counter='+ count
                }); 
                
                c++;
            }else{
                c= 4;
                
                alert("U kunt er alleen 3 selecteren");
                $('.chkAdvanced'+id).removeClass("checkedAdvanced");
                $('.chk'+id).removeClass("checked");
                $('.checkbox'+id).prop("checked", false);
            }
        }
			
        if( !$('.checkbox'+id).attr('checked') ){
           
            
                       
            community = $('#community'+id).val();
           
            if(c > 0 && c <= 3){
                $.ajax({
                    url: '<?php echo(base_url('selecties/verwijderJquerySelectie')); ?>',
                    type: 'post',
                    data: 'community='+ community                    
                }); 
                           
                         
            }
            c--;
        }
    }

</script>
<h2>selecties</h2>
<?php if ($pageName == 'search') { ?>
    <div id="searchForm">

        <a   href="<?php echo(base_url("selecties")); ?>"><button type="button" class="vorige"></button></a>
        <form method="post" action="<?php echo(base_url('selecties/zoeken')); ?>">

            <input class="roundedSearch" type="search" name="search" placeholder="zoeken..."/>
        </form>
    </div>
    <?php
}


if (!empty($query) && ($pageName == 'advancedSearch' || $pageName == 'search')) {
    if($pageName == 'advancedSearch'){
    ?>
    <a   href="<?php echo(base_url("selecties")); ?>"><button type="button" class="vorige2"></button></a>
    <?php
    }
    $id = 0;
    foreach ($query->result() as $row) {
        if (!($row->Naam == $this->session->userdata('gemeente1') || $row->Naam == $this->session->userdata('gemeente2') || $row->Naam == $this->session->userdata('gemeente3'))) {
            ?>

            <?php
            if ($pageName == 'advancedSearch') {
                ?>
                <div class="box" onclick="divClick(<?php echo $id; ?>, c)" >
                    <div class="inputbox">
                        <div class="communityName"><b>gemeente: </b><?php echo( $row->Naam) ?><input type="hidden" id="community<?php echo $id; ?>" name="community" value="<?php echo($row->Naam) ?>" /></div>

                        <div class="data">
                            <table>
                                <tr>
                                    <td ><b>centrum functie: </b><?php echo($row->Centrum) ?></td>
                                    <td><b>provincie: </b><?php echo($provinces[$row->Provincie]) ?></td>
                                </tr>
                                <tr>
                                    <td><b>sociale structuur: </b><?php echo($row->Sociaal) ?></td>                                
                                    <td><b>inwoners: </b><?php echo($row->Inwoners) ?></td>
                                </tr>
                            </table>
                        </div>
                        <input type="checkbox"  class="checkbox<?php echo $id; ?>"name="option"/>
                    </div>
                    <div class="chkAdvanced<?php echo $id; ?>"></div>

                </div>
                <?php
                $id++;
            } else if ($pageName == 'search') {
                ?>


                <div class="box2" onclick="divClick(<?php echo $id; ?>, c)" >
                    <div class="inputbox">
                        <div class="resultName">
                            <b><?php echo( $row->Naam) ?></b><input type="hidden" id="community<?php echo $id; ?>" name="community" value="<?php echo($row->Naam) ?>" />
                        </div>
                        <input type="checkbox"  class="checkbox<?php echo $id; ?>"name="option"/>
                    </div>
                    <div class="chk<?php echo $id; ?>"></div>
                </div>



                <?php
                $id++;
            }
            ?>

            <?php
        }
    }
}
?>





